/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package pt.our.angemc.datatypes;

import java.util.ArrayList;

/**
 *
 * @author piskeiro
 */

public class SymbolsSequence extends Symbol{
    /**
     * example:
     *           ('|' elements)*
     */
    private final String openEnclosure = "(";
    private final String closeEnclosure = ")";

    private ArrayList<Symbol> symbols;

    public SymbolsSequence(String name, Multiplier multiplier, ArrayList<Symbol> symbols,boolean notMatch) {
        super(name, multiplier,notMatch);
        this.symbols = symbols;
    }

    public ArrayList<Symbol> getSymbols() {
        return symbols;
    }

    public void setSymbols(ArrayList<Symbol> simbols) {
        this.symbols = simbols;
    }

    public void addSymbol(Symbol symbol){
        symbols.add(symbol);
    }

    public SymbolsSequence clone(){
        ArrayList<Symbol> newSymbols = new ArrayList<Symbol>();
        for(Symbol symbol : this.symbols){
            newSymbols.add(symbol.clone());
        }
        SymbolsSequence symbolsSequence = new SymbolsSequence(getName(), getMultiplier(), newSymbols, this.isNotMatch());
        return symbolsSequence;
    }

    @Override
    public String toString(){
        StringBuffer sb = new StringBuffer();
        sb.append(openEnclosure);
        for(Symbol symbol : symbols){
            sb.append(symbol.toString()+" ");
        }
        if(sb.length()>1){
            sb.deleteCharAt(sb.length()-1);
        }
        sb.append(closeEnclosure+this.getMultiplier().getMultiplierRepresentationAsString());
        return sb.toString().trim();
    }

    @Override
    public boolean equals(Object obj) {
        if (obj == null) {
            return false;
        }
        if (getClass() != obj.getClass()) {
            return false;
        }
        final SymbolsSequence other = (SymbolsSequence) obj;
        if (this.symbols != other.symbols && (this.symbols == null || !this.symbols.equals(other.symbols))) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 3;
        hash = 29 * hash + (this.symbols != null ? this.symbols.hashCode() : 0);
        return hash;
    }


}
